﻿$(function () {
    var tabs;
    var expand = 0;


    var position = $(window).scrollTop();
    var header_h = $("#header").height();
    var header_ct = $("#header").html();
    var iden1 = 0;
    var IsIChrome = navigator.userAgent.search("CriOS") >= 0 ? true : false;
    var IsIos7 = /(iPhone|iPod|iPad);.*CPU.*OS 7_\d/i.test(navigator.userAgent);
    if (IsIChrome && IsIos7) IsIChrome = false; //neu la ios 7 thi nhu safari

    document.addEventListener("touchmove", ScrollStart, false);
    document.addEventListener("scroll", Scroll, false);

    function ScrollStart() {

        //start of scroll event for iOS
        if (expand == 0)
        {
            var scroll = $(window).scrollTop();
            if (scroll > position)
            {
                if ($(window).scrollTop() > header_h)
                {
                    $("#header_float").hide();
                    iden1 = 0;
                }
            } else if (position > scroll + 3)
            {
                if ($(window).scrollTop() > header_h)
                {
                    $("#header_float").show();
                    if (iden1 == 0)
                    {
                        if (!$("#header_float").hasClass("fix_header"))
                            $("#header_float").addClass("fix_header");
                        iden1 = 1;
                    }
                }
                else $("#header_float").hide();
            }
            position = scroll;
        }
    }

    function Scroll() {
        //end of scroll event for iOS
        //and
        //start/end of scroll event for other browsers
        if (expand == 0)
        {
            var scroll = $(window).scrollTop();
            if (scroll > position)
            {
                if ($(window).scrollTop() > header_h)
                {
                    $("#header_float").hide();
                    iden1 = 0;
                }
            } else if (position > scroll + 3)
            {
                if ($(window).scrollTop() > header_h)
                {
                    $("#header_float").show();
                    if (IsIChrome)
                    {
                        $('#header_float').css('margin-top', '40px ');
                    }
                    if (iden1 == 0)
                    {
                        if (!$("#header_float").hasClass("fix_header"))
                            $("#header_float").addClass("fix_header");
                        iden1 = 1;
                    }
                }
                else $("#header_float").hide();
            }
            position = scroll;
        }
    }

});

function setTab(elem) {
    $("#tabSelector a").removeClass("active");
    $(elem).find("a").addClass("active");
}